<?php
header("content-type:text/html; charset=utf-8");
//获取subper.php传递过来的用户名以及商品类型
$name=$_GET['name'];
$type=$_GET['type'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仓库界面</title>
</head>
<style>
   .main{
    width:70%;
    height:659px;
    border: 2px solid green;
    margin:20px auto;
    line-height:50px;
    padding-left: 30px;
    position: relative;

   }
   .main h4{
       margin:0px;
       text-align:center;
   }
   .main table th{
    width:200px;
    height:30px;
}
.main table{
    margin:10px auto;
    text-align: center;
}
.fyann{
    
    width:100%;
    height:40px;
    margin:0 auto;
    text-align:center;
    position: absolute;
    bottom:10px;
    
}
.fyann button{
    background-color:orange;
    border:none;
    margin-right:10px;
}
/* 移动端样式代码 */
@media screen and (max-width:500px){
 .main{
     width:90%;
     height:1700px;
 }
    }
</style>
<body>
    <div class=main>
    <?php
    $name=$_GET['name'];
    $type=$_GET['type'];
    echo "<h4>$type</h4>";
   echo "<hr>";
    $serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
    mysql_query("'set names 'utf-8'");
    $dbLink=@mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
     $rs=mysql_query("select count(*) from product where inputname='$name' and producttype='$type'");
     $rows=mysql_fetch_row($rs);
     $recordcount=$rows[0];//总记录数
    $pagesize=4;//页面显示条数
    $pagecount=ceil($recordcount/$pagesize);//总页数
    //获得传递页码
  $pageno=isset($_GET['pageno'])?$_GET['pageno']:1;//如果没有传递 则为第一页
   
  if($pageno > $pagecount){
    $pageno = $pagecount;
     }
  else if($pageno < 1){
    $pageno=1;
 }
 

  //获得当前页的起始位置
  $startno=($pageno-1)*$pagesize;


    $select="select * from product where inputname='$name' and producttype='$type' limit $startno,$pagesize";
    $sqlsp=mysql_query($select);
    

     if($recordcount<='0'){
       echo "您的仓库中没有此类商品";
          }else{       
    echo "<table border=1 rules=all>
    <tr>
    <th style=background-color:#0fd2de>商品名称
    <th style=background-color:#0fd2de>商品类型
    <th style=background-color:#0fd2de>价格
    <th style=background-color:#0fd2de>数量
    <th style=background-color:#0fd2de>图片
    </tr>";
    while($db=mysql_fetch_array($sqlsp)){
        echo "<tr><td>";
         echo $db['productname']." ";
         echo "<td>";
         echo $db['producttype']." ";
         echo "<td>";
         echo $db['productprice']."<br/>";
         echo "<td>";
         echo $db['productcount']."<br/>";
         echo "<td>";
         
        $a=$db['picturesrc'];
         echo "<img src='$a' width=100px height=100px />";
         echo "</td></tr>"; 
     }
     echo" </table>";
     echo "总商品数：".$recordcount." ";
     echo "总页数：".$pagecount;
    }
    ?>
    <?php   mysql_close($serverLink);?>
  
<div>
    <?php
    //分页按钮
    echo'<div class=fyann>';
    echo '<a href="repertory.php?name='.$name.'&type='.$type.'&pageno=1"><button>首页</button></a>';
    echo '<a href="repertory.php?name='.$name.'&type='.$type.'&pageno='.($pageno-1).'"><button>上一页</button></a>';
    echo '<a href="repertory.php?name='.$name.'$type='.$type.'$pageno='.($pageno+1).'"><button>下一页</button></a>';
    echo '<a href="repertory.php?name='.$name.'&type='.$type.'&pageno='.$pagecount.'"><button>末页</button></a>';
    echo '</div>';
    ?>
</div> 



 </div>
</body>
</html>